package ar.com.tallerdos.smartdinner.sync;

import android.os.AsyncTask;
import ar.com.tallerdos.smartdinner.activity.ComidasLista;
import ar.com.tallerdos.smartdinner.model.Comida;

public class Notificador extends AsyncTask<Void, Void, Void> {
	
	private int actualizar = 0;
	private ComidasLista activity;
		
	public Notificador(ComidasLista mainActivity) {
		activity = mainActivity;
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
	}

	@Override
	protected Void doInBackground(Void... params) {
		
		actualizar = 0;
		for(Comida comida: activity.getComidas()){
			if(comida.getNotificacion() == 1){
				actualizar = 1;
				break;
			}
		}
		return null;

	}

	@Override
	protected void onPostExecute(Void result) {
		// this method will be running on UI thread
		super.onPostExecute(result);
		if(actualizar == 1){
			activity.getComidasAdapter().notifyDataSetChanged();
			actualizar = 0;
		}
	}
}
